package com.mobilesafe.engine;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import com.mobilesafe.domain.UpdateInfo;

import android.content.Context;
import android.util.Log;

public class UpdateInfoService {
	private static final String TAG = "UpdataInfoService";
	private Context context;

	public UpdateInfoService(Context context) {
		this.context = context;
	}

	/**
	 * 
	 * @param 服务器路径url对应的Id
	 * @return UpdataInfo
	 * @throws Exception
	 */
	public UpdateInfo getUpdataInfo(int UrlId) throws Exception {
		String path = context.getResources().getString(UrlId);
		URL url = new URL(path);
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		conn.setConnectTimeout(3000);
		conn.setRequestMethod("GET");
		// int code = conn.getResponseCode();
		InputStream is = null;

		is = conn.getInputStream();
		Log.i(TAG, "更新信息获取成功");

		return UpdateInfoParser.getUpdataInfo(is);
	}
}
